package com.luojing.springcloud.rocketmq;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

/**
 * @author luojing
 * @create 2018/10/24 10:38 AM
 **/
public class ScheduledProducer {
  public static void main(String[] args) throws Exception {
    // Instantiate a producer to send scheduled messages
    DefaultMQProducer producer = new DefaultMQProducer("ExampleProducerGroup");

    producer.setNamesrvAddr("localhost:9876");
    // Launch producer
    producer.start();
    int totalMessagesToSend = 100;
    for (int i = 0; i < totalMessagesToSend; i++) {
      Message message = new Message("TestTopic", ("Hello scheduled message " + i).getBytes());
      // This message will be delivered to consumer 10 seconds later.
      message.setDelayTimeLevel(3);
      // Send the message
      producer.send(message);
    }

    // Shutdown producer after use.
    producer.shutdown();
  }

}
